package be.ipl.pigolo.testUcc;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.junit.Before;
import org.junit.Test;

import be.ipl.pigolo.domaine.Partie;
import be.ipl.pigolo.usecases.GestionPartie;

public class TestAnnuler {

   private static GestionPartie gp ;
   private Partie partie ;
	
	@Before
	public void setUp() throws Exception {
		try {
			Context jndi = new InitialContext();
			gp = (GestionPartie) jndi
					.lookup("ejb:PigoloEAR/PigoloEJB/GestionPartieImpl!be.ipl.pigolo.usecases.GestionPartie");
			assertNotNull(gp);
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void testAnnulerrPartieVide(){
		assertFalse(this.gp.annuler(""));
	}
	
	@Test
	public void testAnnulerPartieEnAttente(){
		partie = new Partie("partie1", 5);
		this.gp.creerPartie(partie.getNom(), 30);
		assertTrue(this.gp.annuler(this.partie.getNom()));
	}
	
	@Test
	public void testAnnulerPartieValide(){
		partie = new Partie("partie2", 5);
		this.gp.creerPartie(partie.getNom(), 30);
		this.partie.commencerPartie();
		assertTrue(this.gp.annuler(this.partie.getNom()));
	}
	
	
}

